<?
require 'Snoopy.class.php';

class Gcy extends Snoopy{

	
	public function __construct(){
		
		
	}
	
	protected function snoo(){
		$snoopy = $this;
		/* $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"; //伪装浏览器  
		 
		$snoopy->referer = "http://www.ewt360.com"; //伪装来源页地址 http_referer
		$snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息   
		$snoopy->rawheaders["X_FORWARDED_FOR"] = "218.59.144.147"; */

		$snoopy->cookies['yunsuo_session_verify'] = "f51831b39507c453ddfe67f43f377e84";
		$snoopy->cookies['Hm_lvt_779e45300d963a3909b7ae83f85537e7'] = '1541410822; Hm_lpvt_779e45300d963a3909b7ae83f85537e7=1541411378';
		$snoopy->cookies['security_session_mid_verify'] = '0fc9ff14b7538dcd3fb032b22d0f280b';
		$snoopy->cookies['__RequestVerificationToken'] = '0tfcyssW7f8P26brQTUh5jEVoPeHUUwbbDqAjBcNln9BBKo-HACyWX1vcYlsXZ72n9_pH1-jVpIibaAKPr0jaoIqsh8MI0AOnMJtujfvnC_Gu68no3SZjt11usFi1pgmqjUkel-6SmbfdNGZOvOXQw2';

		/* $snoopy->cookies['sso_key'] = "d847f748fc0d5060.4uateo.9982b.jinzhong";
		$snoopy->cookies['Hm_lvt_6d44073efa951236d799d4fc8aa18779'] = "1476068044";
		$snoopy->cookies['Hm_lpvt_6d44073efa951236d799d4fc8aa18779'] = "1476069941";
		$snoopy->cookies['ESessionID'] = "82B6F84AF950400A938F8E54AE14BB18";
		$snoopy->cookies['BD_CK_SAM'] = 1;
		$snoopy->cookies['BDRCVFR[gltLrB7qNCt]'] = 'mk3SLVN4HKm';
		$snoopy->cookies['sso_token'] = 'b54ff3dfa143fb2e.lkateo.82B6F84A-F950-400A-938F-8E54AE14BB18.jinzhong'; */
		
		return $snoopy;
	}
	
	public function snoopyPost($ur,$post){
	
		$snoo = $this->snoo();
		
		$snoo->submit($ur,$post); //模拟浏览器提交并取得返回结果  
		
		$data = $snoo->results;
		
		return $data;
	}
	
	public function grabU($url){
	
		$snoo = $this->snoo();
		$snoo->fetch($url);
		$data = $snoo->results;
		
		if(!$data)
			return false;
		
		return $data;
	}
	
	public function page($data){
	
		$total='';$page='';$strip='';
		$data = strstr($data,'<div class="page"><div style="float:left;">');
		
		list($data,) = explode('</div><div style="float:right;">',$data);
		preg_match_all('/(\d+)/',$data,$array);
		if(!$array[0])
			return false;
			
		list($total,,$page,$strip) = $array[0];
		
		return array('total'=>$total,'page'=>$page,'strip'=>$strip);
	}
	
	protected function Obtain($data){
		
		$data = strstr($data,'<tbody>');
		list($data,) = explode('</tbody>',$data);
		
		preg_match_all('/<tr.*>(.+)<\/tr>/isU',$data,$tabTr);
		$tabTrData = $tabTr[1];
		if(!$tabTrData)return false;
		
		return $tabTrData;
	}
	
	public function sel_str_the($data){
		
		$tabTrData = $this->Obtain($data);
		$tabTdData = array();
		
		foreach($tabTrData as $key=>$value){
			preg_match_all('/<td.*>(.+)<\/td>/isU',$value,$tabTd);
			
			foreach($tabTd[1] as $tdK=>$tdV){
				$tabTd[1][$tdK] = $this->deleteHtml($tdV);
			}

			//标题 	上传者 	分类 学科	年级	大小	上传日期
			list($title,$uploader,$class,$edusys,$grade,$size,$date) = $tabTd[1];
			
			$tabTdData[$key] = array(
									'title'=>$title,
									'uploader'=>$uploader,
									'class'=>$class,
									'edusys'=>$edusys,
									'grade'=>$grade,
									'size'=>$size,
									'date'=>$date,
								);
		}
		
		return $tabTdData;
	}
	
	public function login($url,$data){
		
		$res = $this->snoopyPost($url,$data);
		
		return $res;
	}
	
	public function deleteHtml($str) {
		$str = strip_tags($str);
		$str = trim($str);
		$str = ereg_replace(">","",$str);
		$str = ereg_replace("\t","",$str);
		$str = ereg_replace("\r\n","",$str);
		$str = ereg_replace("\r","",$str);
		$str = ereg_replace("\n","",$str);
		$str = ereg_replace("    ","",$str);
		return trim($str);
	}
}
?>